FROM golang:1.18.3-alpine As builder

ENV GO111MODULE=on

ENV GOPROXY=https://goproxy.cn/

WORKDIR /app

# 构建脚本命令
ADD ./go_shell/vpn_checkin /app
RUN go build -o ./shell/checkin/checkin ./main/main.go \
    && cp ./start.sh ./shell/checkin/start.sh

## 进入项目文件夹
COPY go.mod .
COPY go.sum .
## 下载包
RUN go mod download
# 项目复制到容器里
ADD . /app
# 编译go项目
RUN go build -o ./buildWorker worker/main/worker.go
# docker镜像分层构建 可以区分编译环境和运行环境
FROM alpine:3.16.0

WORKDIR /app

COPY --from=builder /app/buildWorker/worker .
COPY --from=builder /app/worker/worker.json .
COPY --from=builder /app/shell /app/shell
RUN chmod +x /app/shell/checkin/start.sh
RUN chmod +x /app/shell/checkin/checkin

## 启动go项目
CMD ["sh","-c","/app/worker -config ./worker.json"]
